// pages/gift_detail/gift_detail.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: [
      '../image/product_detail/pro1.png',
      '../image/product_detail/pro1.png',
      '../image/product_detail/pro1.png'
    ],
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    duihuan_success: false,
    zhe: false,
    R_code:''
  },
  hide_model:function(e){
    this.setData({
      duihuan_success: false,
      zhe: false
    })
  },
  dui:function(){
    var that = this;
    console.log(app.globalData.opid)
    console.log(that.data.detail.goods_id)
    console.log(that.data.detail.exchange_integral)
    wx.showModal({
      title: '提示',
      content: '确定兑换吗？',
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定')
          wx.request({
            url: app.globalData.url + 'ziyu.php?Action=duihuanliping',
            data: {
              openid: app.globalData.opid,
              R_productid: that.data.detail.goods_id,
              R_amount: that.data.detail.exchange_integral
            },
            success: function (res) {
              console.log(res)
              if (res.data.success == 0) {
                wx.showToast({
                  title: '账户余额不足',
                  icon: 'none'
                })
              } else {
                that.setData({
                  R_code: res.data.R_code,
                  duihuan_success: true,
                  zhe: true
                })
              }

            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
   
    
  },
  // 去商品详情
  go_shop_detail: function (e) {
    console.log(e.currentTarget.dataset.id)
    wx.navigateTo({
      url: '../product_detail/product_detail?id=' + e.currentTarget.dataset.id,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.request({
      url: app.globalData.url+'exchange.php?&act=view',
      data:{
        id:options.id
      },
      success:function(res){
       console.log(res)
       that.setData({
         detail:res.data
       })
       
      }
    })
    // 推荐
    wx.request({
      url: app.globalData.url + 'ziyu.php?Action=product',
      success: function (res) {
        console.log('商城')
        console.log(res)
        that.setData({
          shop_list: res.data
        })
      }
    })
    // 图片
    wx.request({
      url: app.globalData.url +'exchange.php?&act=pictures',
      data: {
        id: options.id
      },
      success: function (res) {
        console.log(res)
        that.setData({
          imgUrls: res.data
        })

      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})